package com.pan.behavioral.observer.traffic.lane;

import com.pan.behavioral.observer.pattern.Observer;
import com.pan.behavioral.observer.pattern.Subject;
import com.pan.behavioral.observer.traffic.TrafficLight;

public abstract class Lane implements Observer<String>{

    private TrafficLight trafficLight;
    private String laneStatus = "stop";

    @Override
    public final void setSubject(Subject subject) {
        if (!(subject instanceof TrafficLight)){
            throw new RuntimeException("Subject Error: Lane only read TrafficLight. ");
        }
        this.trafficLight = (TrafficLight) subject;
    }

    protected final String getTrafficLightStatus(){
        return trafficLight.getStatus();
    }
    protected final String getLaneStatus(){
        return laneStatus;
    }

    protected void updateLaneStatus(String trafficSignal){
        if (trafficSignal.toLowerCase().equals("red")){
            laneStatus = "stop";
        } else if (trafficSignal.toLowerCase().equals("yellow")) {
            laneStatus = "slow";
        } else if (trafficSignal.toLowerCase().equals("green")) {
            laneStatus = "go";
        }
    }


    @Override
    public abstract void receive();


}
